package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.entity.Result;
import com.itheima.mapper.PermissionMapper;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;

import static com.itheima.constant.MessageConstant.QUERY_PERMISSION_FAIL;
import static com.itheima.constant.MessageConstant.QUERY_PERMISSION_SUCCESS;

@Service(version = "1.0", interfaceClass = PermissionService.class)
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    PermissionMapper permissionMapper;

    @Override
    public Result findAll() {
        try {
            List<Permission> permissionList = permissionMapper.findAllPermission();
            return Result.success(QUERY_PERMISSION_SUCCESS, permissionList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Result.fail(QUERY_PERMISSION_FAIL);
    }

    @Override
    public Result findPerByModuleId(Integer[] menuIds) {
        List<Permission> permissionList=null;
        for (Integer menuId : menuIds) {
            permissionList  = permissionMapper.findPerMissionByModuleIds(menuId);
        }

        return Result.success(QUERY_PERMISSION_SUCCESS,permissionList);
    }
}
